package com.example.demo.interceptor;

import com.alibaba.fastjson.JSON;
import com.example.demo.entity.ResultVo;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 对全局的返回异常进行处理
 * Created by tanjun on 2022-01-09.
 */

@RestControllerAdvice
public class DefaultGlobalExceptionHandle {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResultVo handle(Exception e,HttpServletResponse response) {
        ResultVo resultVo=new ResultVo();
        e.printStackTrace();
        resultVo.setServiceSuccess(false);
        resultVo.setErrorMsg(e.getMessage());
        return resultVo;
    }

}
